package com.yaozheng.vocationaltraining.adapter.userinfo;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.yaozheng.vocationaltraining.activity.BaseActivity;
import com.yaozheng.vocationaltraining.utils.TypeUtils;
import com.yaozheng.vocationaltraining.view.userinfo.ItemListViewSelectView;
import com.yaozheng.vocationaltraining.view.userinfo.ItemListViewSelectView_;

import net.sf.json.JSONArray;

/**
 * 选择列表对话框设备器
 */
public class ListViewSelectDialogAdapter extends BaseAdapter {
    JSONArray dataList;
    BaseActivity baseActivity;

    public ListViewSelectDialogAdapter(BaseActivity baseActivity, JSONArray dataList) {
        this.baseActivity = baseActivity;
        this.dataList = dataList;
    }

    public JSONArray getDataList() {
        return dataList;
    }

    public void setDataList(JSONArray dataList) {
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return TypeUtils.getJsonArraySize(dataList);
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ItemListViewSelectView itemListViewSelectView = null;
        if (convertView == null) {
            itemListViewSelectView = ItemListViewSelectView_.build(baseActivity);
        } else {
            itemListViewSelectView = (ItemListViewSelectView) convertView;
        }

        itemListViewSelectView.loadData(position, TypeUtils.getJsonObject(dataList, position));
        return itemListViewSelectView;
    }
}
